using System;
using System.Data;

using SqlHelperForCry.Common;

namespace Torch.WL.Entity
{
    [Table("Tb_Sys_UserRoles", "UR_ID", "Torch.WL.ConnectionString")]
	public class Tb_Sys_UserRoles : Info
	{
		#region SQL column name consts 
		public const string SQLCOL_UR_ID = "UR_ID";
		public const string SQLCOL_USERID = "UserID";
		public const string SQLCOL_ROLEID = "RoleID";
		#endregion


		#region Contructors
		/// <summary>
		/// Construct empty entity
		/// </summary>
		public Tb_Sys_UserRoles () {}

		/// <summary>
		/// Construct entity by primary key, other fields will be assigned by 
		/// "Load" method.
		/// </summary>
		public Tb_Sys_UserRoles (int UR_ID)
		{
			this.UR_ID = UR_ID;
		}
		#endregion

		public override void Init (DataRow row)
		{
			UR_ID = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_UR_ID]);
			UserID = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_USERID]);
			RoleID = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_ROLEID]);
		}

		#region Properties 
		#region Property <int> UR_ID
		[Property("UR_ID", 4, SqlDbType.Int, true, true)]
		public int UR_ID 
		{
			get { return _UR_ID; }
			set { _UR_ID = value; }
		}
		private int _UR_ID = int.MinValue;
		#endregion

		#region Property <int> UserID
		[Property("UserID", 4, SqlDbType.Int, false, false)]
		public int UserID 
		{
			get { return _UserID; }
			set { _UserID = value; }
		}
		private int _UserID = int.MinValue;
		#endregion

		#region Property <int> RoleID
		[Property("RoleID", 4, SqlDbType.Int, false, false)]
		public int RoleID 
		{
			get { return _RoleID; }
			set { _RoleID = value; }
		}
		private int _RoleID = int.MinValue;
		#endregion
		#endregion


		public bool LoadByIdentity(int UR_ID)
		{
			return DataAccess.SelectByIdentity(this, Convert.ToInt64(UR_ID));
		}


		public bool DeleteByIdentity()
		{
			return DataAccess.DeleteByIdentity(this);
		}
	}
}
